package com.leetcode.editor.cn.other;

/**
 * @description:
 * @author:
 * @create: 2021-03-30 13:54
 **/
public class AddNum {
    public static void main(String[] args) {
        System.out.println(solve("123","4567"));
    }
    public static String solve (String s, String t) {
        // write code here
        if(s==null||t==null){
            return s==null?t:s;
        }
        char[] arr1=s.toCharArray();
        char[] arr2=t.toCharArray();
        int m=arr1.length-1,n=arr2.length-1;
        StringBuilder builder=new StringBuilder();
        int carry=0;
        while(m>=0||n>=0){
            int v1=m>=0?arr1[m--]-'0':0;
            int v2=n>=0?arr2[n--]-'0':0;
            int sum=v1+v2+carry;
            int val=sum%10;
            carry=sum/10;
            builder.append(val);
        }
        return builder.reverse().toString();
    }
}
